define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            $(".btn-add").data("area",["80%","80%"]);
            $(".btn-edit").data("area",["80%","80%"]);

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pms/pmsroomtype/index' + location.search,
                    add_url: 'pms/pmsroomtype/add',
                    edit_url: 'pms/pmsroomtype/edit',
                    del_url: 'pms/pmsroomtype/del',
                    multi_url: 'pms/pmsroomtype/multi',
                    table: 'pms_room_type',
                }
            });

            var table = $("#table");

            table.on('post-body.bs.table',function(){
                $(".btn-editone").data("area",["80%","80%"]);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                searchFormVisible: true,
                columns: [
                    [
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'monday_price', title: __('Monday_price'), operate: false},
                        {field: 'tuesday_price', title: __('Tuesday_price'), operate: false},
                        {field: 'wednesday_price', title: __('Wednesday_price'), operate: false},
                        {field: 'thursday_price', title: __('Thursday_price'), operate: false},
                        {field: 'friday_price', title: __('Friday_price'), operate: false},
                        {field: 'saturday_price', title: __('Saturday_price'), operate: false},
                        {field: 'sunday_price', title: __('Sunday_price'), operate: false},
                        // {field: 'hour_room_price', title: __('Hour_room_price'), operate: false},
                        // {field: 'timeout_price', title: __('Timeout_price'), operate: false},
                        // {field: 'meal_coupon_num', title: __('Meal_coupon_num'), operate: false},
                        {field: 'deposit', title: __('Deposit'), operate: false},
                        {field: 'state', title: __('State'), searchList: {"0":__('State 0'),"1":__('State 1'),"-1":__('State -1')}, formatter: Table.api.formatter.status},
                        {field: 'updatetime', title: __('Updatetime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'last_editor', title: __('Last_editor'), formatter: function(value, row, index) {
                            return row['last_editor_nickname'];
                        }, operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $('#js_Unifiedprice').click(function(){
                if ($(this).is(':checked'))
                {
                    var price = $('#c-monday_price').val();
                    $('#c-unified_price').val(price);
                    $('.multiple_prices').addClass('hidden');
                    $('#one_price').removeClass('hidden');
                }
                else
                {
                    $('.multiple_prices').removeClass('hidden');
                    $('#one_price').addClass('hidden');
                }
            });

            Controller.api.bindevent();
        },
        edit: function () {
            $('#js_Unifiedprice').click(function(){
                if ($(this).is(':checked'))
                {
                    var price = $('#c-monday_price').val();
                    $('#c-unified_price').val(price);
                    $('.multiple_prices').addClass('hidden');
                    $('#one_price').removeClass('hidden');
                }
                else
                {
                    $('.multiple_prices').removeClass('hidden');
                    $('#one_price').addClass('hidden');
                }
            });

            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});